//
//  String+Extension.swift
//  Sina
//
//  Created by 王杰 on 15/11/25.
//  Copyright © 2015年 王杰. All rights reserved.
//
import Foundation

extension String {
    
     func linhref() -> (link: String?, clienName: String?) {
        
        let pattern = "<a href=\"(.*?)\".*?>(.*?)</a>"
        //在前端 如果遇到需要抛出错误  可以直接强try
        let regex = try! NSRegularExpression(pattern: pattern, options: [])
        
        //返回值
        let result = regex.firstMatchInString(self, options: [], range: NSRange(location: 0, length: characters.count))

        let range2 = result?.rangeAtIndex(1)
        let range3 = result?.rangeAtIndex(2)
        var subStr2: String?
        var subStr3: String?
        if let r2 = range2, r3 = range3 {
            subStr2 = (self as NSString).substringWithRange(r2)
            
            subStr3 = (self as NSString).substringWithRange(r3)
        }
        
        return (subStr2,subStr3)
    }
}